<template>
  <div>
    <div id="slider" class="mui-slider">
      <div
        id="sliderSegmentedControl"
        class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted"
      >
        <div class="mui-scroll">
          <a
            :class="['mui-control-item',item.id===0?'mui-active':'']"
            v-for="item in category"
            :key="item.id"
            @click="getPhotosAll(item.id)"
          >{{item.title}}</a>
        </div>
      </div>
    </div>
    
    <ul class="lazyUl">
      <router-link tag="li" :to="'/home/photoinfo/'+item.id" v-for="item in photoslist" :key="item.id">
        <img v-lazy="item.img_url" />
        <div class="Info">
          <h3 class="info-t">{{item.title}}</h3>
          <div class="info-con">{{item.zhaiyao}}</div>
        </div>
      </router-link>
    </ul>
  </div>
</template>

<script>
import mui from "../../../lib/mui/js/mui.js";

export default {
  data() {
    return {
      category: [],
      photoslist: []
    };
  },
  methods: {
    async getPhotosCategory() {
      const { data } = await this.$http.get("/api/getimgcategory");
      if (data.status === 0) {
        //console.log(data.message);
        data.message.unshift({ title: "全部", id: 0 });
        this.category = data.message;
      }
    },
    async getPhotosAll(id) {
      const { data } = await this.$http.get("/api/getimages/" + id);
      if (data.status === 0) {
        //console.log(data);
        return (this.photoslist = data.message);
      }
    }
  },
  created() {
    this.getPhotosCategory();
    this.getPhotosAll(0);
  },
  mounted() {
    mui(".mui-scroll-wrapper").scroll({
      deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
    });
  }
};
</script>

<style lang="scss" scoped>
.mui-slider {
  touch-action: pan-x;
}

.lazyUl {
  margin: 0;
  padding: 10px;
  list-style: none;
  li {
    background-color: #ccc;
    text-align: center;
    box-shadow: 0 0 7px rgb(113, 93, 204);
    position: relative;
    & + li {
      margin-top: 10px;
    }
    img {
      vertical-align: middle;
      width: 100%;
    }
    img[lazy="loading"] {
      width: 40px;
      height: 300px;
      margin: auto;
    }
  }
}
.Info{
    position: absolute;
    bottom: 0;
    color: wheat;
    background-color: rgba(0,0,0,0.5);
    max-height: 100px;
    overflow: hidden;
    .info-t{
        font-size: 14px;
        text-align: left;
        font-weight: 200;
        color: rgba(157, 197, 243, 0.726);
    }
    .info-con{
        font-size: 12px;
        text-align: left;
        //text-indent: 2em;
    }
}
</style>